require 'ctx_rbm'
require 'dict'

torch.setdefaulttensortype('torch.DoubleTensor')

function main()
	-- load dic & embs
	print('load dic & emb')
	local f = torch.DiskFile(dic_emb_path, 'r')
	dic 	= f:readObject()	setmetatable(dic, Dict_mt)
	cwemb 	= f:readObject()
	f:close()

	-- load data
	print('load data')
	f = torch.DiskFile(data_path, 'r')
	f:binary()
	data	= f:readObject()
	wlist	= f:readObject()
	cwlist	= f:readObject()
	f:close()
	print(data:size())

	-- load sampler storage
	print('load sampler storage')
	f = torch.DiskFile(sampler_storage_path, 'r')
	f:binary()
	sampler_storage = f:readObject()
	f:close()

	nctxwords = 4
	hiddim = 200
	compdim = data:size(1) - nctxwords

	-- training
	--data = shuffle(data)

		print('training...')

		init_momentum = 0.9
		final_momentum = 0.9
		eps = 0.01
		weightcost = 0.001
		chainlen = 300

		nepoch = 100
		batchsize = 100

		local model = CtxRBM:new(cwemb, nctxwords, hiddim, compdim, cwlist)
	
		print('training rbms...')
		model:train(data, nepoch, batchsize, init_momentum, final_momentum, 
					eps, weightcost, chainlen, sampler_storage)

end

if #arg == 3 then
	dic_emb_path = arg[1]
	data_path = arg[2]
	sampler_storage_path = arg[3]
	main()
else 
	print("<dic_emb_path> <ctx_data_path> <sampler_storage_path>")
end


